<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>找回密码</title>
        <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
        <meta content="yes" name="apple-mobile-web-app-capable"/>
        <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
        <meta content="telephone=no" name="format-detection"/>
        <link href="/css/login.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="/js/jquery.min.js" ></script>
        <link href="/css/aui/aui.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="/js/aui/aui-dialog.js" ></script>

    </head>
    <body>
        <section class="aui-flexView">
            <header class="aui-navBar aui-navBar-fixed b-line">
                <a href="login" class="aui-navBar-item">
                    <i class="icon icon-return"></i>
                </a>
                <div class="aui-center">
                    <span class="aui-center-title" style="font-size: 16px;">找回密码</span>
                </div>
            </header>#include('header.html')
            <section class="aui-scrollView">
                <div class="aui-code-box">
                    <form action="" method="post" onsubmit="return checkform()">
                        
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="uEmail" value="" id="uemail" autocomplete="off" placeholder="邮箱"/>
                        </p>
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="emailcode" id="ecode" autocomplete="off" placeholder="验证码"/>
                            <button style="padding: 0;width: 90px;height: 30px; line-height: 30px;font-size: 15px;margin-bottom: 5px;position: absolute; top: 10px;right: 15px;" type="button" class="fr am-btn am-btn-xm am-round am-btn-success getemailcode" id="getemailcode">获取验证码</button>
                        </p>
                        <p class="aui-code-line aui-code-line-clear">
                            <i class="aui-show pass operate-eye-open"></i>
                            <input type="password" class="aui-code-line-input password" name="uPassword" maxlength="18" id="mima1" placeholder="新密码" value="">
                        </p>
                        <p class="aui-code-line aui-code-line-clear">
                            <i class="aui-show pass1  operate-eye-open"></i>
                            <input type="password" class="aui-code-line-input password1" id="mima2" placeholder="确认密码" value="">
                        </p>
                        <div class="aui-code-btn">
                            <button style="font-size: 16px;">提交</button>
                        </div>
                    </form>
                </div>
            </section>
        </section>
        <script type="text/javascript">
            $('.pass').click(function() {
                var pass_type = $('input.password').attr('type');

                if (pass_type === 'password') {
                    $('input.password').attr('type', 'text');
                    $('.pass').removeClass('operate-eye-open').addClass('operate-eye-close');
                } else {
                    $('input.password').attr('type', 'password');
                    $('.pass').removeClass('operate-eye-close').addClass('operate-eye-open');
                }
            })
            $('.pass1').click(function() {
                var pass_type = $('input.password1').attr('type');

                if (pass_type === 'password') {
                    $('input.password1').attr('type', 'text');
                    $('.pass1').removeClass('operate-eye-open').addClass('operate-eye-close');
                } else {
                    $('input.password1').attr('type', 'password');
                    $('.pass1').removeClass('operate-eye-close').addClass('operate-eye-open');
                }
            })
        </script>

                <script type="text/javascript">
                    var dialog = new auiDialog({})
                        function checkform(){

                            var str=document.getElementById("uemail").value;
                            var reg=/^([a-zA-Z0-9]+[-_.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[-_.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,6}$/;
                            // var reg=/^[a-z0-9](\w|\.|-)*@([a-z0-9]+-?[a-z0-9]+\.){1,3}[a-z]{2,4}$/i;
                            if(reg.test(str)==false){
                                dialog.alert({
                                        // title:"用户名",
                                        msg:'请输入有效的邮箱格式！',
                                        buttons:['确定']
                                    },function(ret){
                                        console.log(ret)
                                    });
                                return false;
                            }

                             
                            var pass1=document.getElementById("mima1").value;
                            var pass2=document.getElementById("mima2").value;
                            if(pass1==""||pass1.length<6){
                                dialog.alert({
                                        // title:"用户名",
                                        msg:'密码长度不少于6个字符！',
                                        buttons:['确定']
                                    },function(ret){
                                        console.log(ret)
                                    });
                                return false;
                            }
                            if(pass1!=pass2){
                                dialog.alert({
                                        // title:"用户名",
                                        msg:'两次密码不一致！',
                                        buttons:['确定']
                                    },function(ret){
                                        console.log(ret)
                                    });
                                return false;
                            }
                            $.ajax({
                                url:"doforget",
                                dataType:"json",
                                type:"post",
                                data:$("form").serialize(),
                                success:function(result){
                                    if(result.status=="1"){
                                        dialog.alert({
                                            msg:'密码重置成功。',
                                            buttons:['确定']
                                        },function(ret){
                                            location.href="login";
                                        });
                                    }
                                    else {
                                        dialog.alert({
                                            msg:''+result.tips,
                                            buttons:['确定']
                                        });
                                    }
                                },
                                error:function(result){
                                    console.log(result);
                                    dialog.alert({
                                        msg:'系统繁忙！',
                                        buttons:['确定']
                                    });
                                }
                            });
                            return false;
                        }
                    </script>
        <script type="text/javascript">  //获取邮箱验证码
        var countdown=-1;
        $(".getemailcode").click(function(){
            if(!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($("#uemail").val())){
                $("#uemail").focus();
                dialog.alert({
                    msg:'请输入有效的邮箱地址！',
                    buttons:['确定']
                },function(ret){
                    console.log(ret)
                });
                return false;
            };
            if (countdown<1) {
                $.ajax({
                    url:"ecode_forget",
                    dataType:"json",
                    type:"post",
                    data:$("form").serialize(),
                    success:function(result){
                        if(result.status=="1"){
                            countdown = 60;
                            settime($("#getemailcode"));
                            dialog.alert({
                                msg:'验证码已发送至您的邮箱，请注意查收。',
                                buttons:['确定']
                            });
                        }
                        else {
                            dialog.alert({
                                msg:''+result.tips,
                                buttons:['确定']
                            });
                        }
                    },
                    error:function(result){
                        console.log(result);
                        dialog.alert({
                            msg:'系统繁忙！',
                            buttons:['确定']
                        });
                    }
                });
            }
        });
        function settime(obj) {
            if (countdown == 0) {
                obj.removeClass("layui-btn-disabled");
                obj.addClass("getemailcode");
                obj.html("获取验证码");
                return;
            } else if(countdown > 0){
                obj.addClass("layui-btn-disabled");
                obj.removeClass("getemailcode");
                obj.html(countdown + "秒后重获");
                countdown--;
            }
        }
        setInterval("settime($(\"#getemailcode\"))",1000);
        </script>
    </body>
</html>
